﻿using System;

namespace SilverlightTetris_M10CDE.Web
{
    /// <summary>
    /// A class that is used to generate shapes for use in the game
    /// </summary>
    public class ShapeFactory
    {
        Random myRand;

        /// <summary>
        /// constructor
        /// </summary>
        public ShapeFactory()
        {
            myRand = new Random();
        }

        /// <summary>
        /// Returns a randomly selected shape
        /// </summary>
        /// <returns>a shape object</returns>
        public Shape getShape()
        {
            int shapeType = myRand.Next(1, 8);  //generate a number between x and x, used to choose a shape semi-randomly
            return createShape(shapeType);
        }

        /// <summary>
        /// Helper method to condense code necessary insode getShape method
        /// </summary>
        /// <param name="colour"></param>
        /// <param name="type"></param>
        /// <returns>a shape object</returns>
        private Shape createShape(int shapeType)
        {
            try
            {
                switch (shapeType)
                {
                    case 1:
                        {
                            Shape myShape = new IShape();      //
                            return myShape;
                        }
                    case 2:
                        {
                            Shape myShape = new JShape();
                            return myShape;
                        }
                    case 3:
                        {
                            Shape myShape = new LShape();
                            return myShape;
                        }
                    case 4:
                        {
                            Shape myShape = new OShape();
                            return myShape;
                        }
                    case 5:
                        {
                            Shape myShape = new SShape();
                            return myShape;
                        }
                    case 6:
                        {
                            Shape myShape = new TShape();
                            return myShape;
                        }
                    case 7:
                        {
                            Shape myShape = new ZShape();
                            return myShape;
                        }
                }
            }
            catch (Exception ex)
            {
                String error = ex.ToString();
            }
            Shape aShape = new TShape();      // necessary if the switch statement fails
            return aShape;                     // return a Tshape if all others fail
        }
    }
}